package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.stark.pmu.bean.FilterItem;
import com.stark.pmu.bean.FilterType;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.PicConvertActivity;
import flc.ast.adapter.FilterAdapter;
import flc.ast.bean.FilterBean;
import flc.ast.databinding.FragmentPicFilterBinding;
import stark.common.basic.base.BaseNoModelFragment;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link PicFilterFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class PicFilterFragment extends BaseNoModelFragment<FragmentPicFilterBinding> {

    private FilterAdapter filterAdapter;
    private int oldPosition=0;

    @Override
    protected int onCreate() {
        return R.layout.fragment_pic_filter;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        filterAdapter.getItem(oldPosition).setSelected(false);
        oldPosition = position;
        filterAdapter.getItem(position).setSelected(true);
        filterAdapter.notifyDataSetChanged();
        //设置滤镜
        PicConvertActivity.mMoviePresenter.setFilter(filterAdapter.getItem(position));
    }

    @Override
    protected void initData() {
        List<FilterItem> listFilter = new ArrayList<>();
        listFilter.add(new FilterItem(R.drawable.filter_1, "无", FilterType.NONE));
        listFilter.add(new FilterItem(R.drawable.filter_2, "黑白", FilterType.GRAY));
        listFilter.add(new FilterItem(R.drawable.filter_3, "下雪", FilterType.SNOW));
        listFilter.add(new FilterItem(R.drawable.filter_4, "水彩", FilterType.KUWAHARA));
        listFilter.add(new FilterItem(R.drawable.filter_5, "复古", FilterType.LUT1));
        listFilter.add(new FilterItem(R.drawable.filter_6, "油墨", FilterType.LUT2));
        listFilter.add(new FilterItem(R.drawable.filter_7, "石雕", FilterType.CAMEO));
        listFilter.add(new FilterItem(R.drawable.filter_8, "浓烈", FilterType.LUT3));
        listFilter.add(new FilterItem(R.drawable.filter_9, "淡雅", FilterType.LUT5));
        listFilter.add(new FilterItem(R.drawable.filter_10, "减色", FilterType.LUT4));
        mDataBinding.rvPicFilterList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        filterAdapter = new FilterAdapter();
        filterAdapter.setList(listFilter);
        mDataBinding.rvPicFilterList.setAdapter(filterAdapter);
        filterAdapter.setOnItemClickListener(this);
    }
}